package com.ayu.commentbackend.mapper;

import com.ayu.commentbackend.pojo.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface UserMapper {

    @Insert("insert into user(username, password, avatar, create_time) VALUES " +
            "(#{username},#{password},#{avatar},#{createTime})")
    void insert(User user);

    @Select("select * from user where username=#{username}")
    User getUserByUsername(String username);

    @Update("update user set password=#{md5Pwd},version=#{version}, update_time=NOW() where id=#{id}")
    void updatePwd(String md5Pwd,Integer version, Long id);

    @Select("select * from user where id=#{id}")
    User getUserById(Long currentId);

    @Select("select version from user where id=#{id}")
    Integer getTokenVersionById(Long id);

    @Select("select username from user where id=#{userId}")
    String getUsernameById(Long userId);

    void update(User user);
}
